# 2024/4/17 上午11:27 HFL
import json

import pytest
import requests

from Utils.RequestUtils import Request
from Utils.utils import get_uuid, common_assert, read_json


# 登录接口

class TestLogin:

    # 生成验证码接口--正向：生成验证码成功
    # @pytest.mark.run(order=0.9)
    def test01_get_verify_code(self):
        # 1.发送接口请求，获取响应数据
        url = 'http://kdtx-test.itheima.net' + '/api/captchaImage'
        resp = requests.get(url=url)

        common_assert(resp, 200, 200, '成功')

    # login_data = [
    #     ("admin", "HM_2023_test", '2', 200, '成功'),
    #     ("", "HM_2023_test", '2', 500, '错误'),
    #     ("admin", "", '2', 500, '错误'),
    #     ("admin", "HM_2023_test", '', 500, '错误')
    # ]

    # 登录接口--正向：登录成功（仅必填）
    # @pytest.mark.parametrize("username,password,verify_code,code,msg", read_json("login_data","login"))
    # def test02_login_success(self, username,password,verify_code,code,msg):
    #     # 发送接口请求，获取响应数据
    #     uuid = get_uuid()
    #     url = 'http://kdtx-test.itheima.net' + '/api/login'
    #     login_json = {"username": username,
    #                   "password": password,
    #                   "code": verify_code,
    #                   "uuid": uuid}
    #     request = Request()
    #     resp_login = request.post(url=url, json=login_json)
    #     print(resp_login.json())
    #     common_assert(resp_login, 200, code, msg)

    @pytest.mark.parametrize("username,password,verify_code,code,msg",read_json("login_data","login"))
    def test02_login(self,username,password,verify_code,code,msg):
        # 发送接口请求，获取响应数据
        url = 'http://kdtx-test.itheima.net' + '/api/login'
        uuid = get_uuid()
        login_json = {
            "username": username,
            "password": password,
            "code": verify_code,
            "uuid": uuid}
        # 响应结果
        request = Request()
        res = request.post(url=url,json=login_json)
        # 断言
        common_assert(res,200,code,msg)

